const jwt = require('jsonwebtoken')
module.exports = (req, res) => {
    // 接收客户端传递过来的 token
    const token = String(req.headers.authorization)
        // 根据 客户端传递过来的 token 进行 解析，解析成功返回一个对象，解析失败直接返回 null
        // 第一个参数是 token 第二个是 私钥 自己定义 
    const username = jwt.decode(token, 'xiaoke')
    if (username.role != 'admin') {
        let arr = [{
                id: 1,
                authName: "个人中心",
                icon: "el-icon-s-custom",
                children: [{
                        id: 1.1,
                        authName: "我的相册",
                        path: "/album"
                    },
                    {
                        id: 1.2,
                        authName: '图片详情',
                        path: "/details"
                    },
                    {
                        id: 1.3,
                        authName: '卡密兑换',
                        path: "/cami"
                    },
                ]
            },
            {
                id: 2,
                authName: "个人资料",
                icon: "el-icon-s-check",
                children: [{
                    id: 2.1,
                    authName: "修改密码",
                    path: '/editpwd'
                }]
            },
            {
                id: 3,
                authName: "API接口",
                icon: "el-icon-key",
                children: [{
                    id: 3.1,
                    authName: "我的API",
                    path: '/api'
                }]
            }

        ]
        res.sendResult(arr, 200, '获取成功！')
        return
    } else {

        let arr = [{
                id: 1,
                authName: "个人中心",
                icon: "el-icon-s-custom",
                children: [{
                        id: 1.1,
                        authName: "我的相册",

                        path: "/album"
                    },
                    {
                        id: 1.2,
                        authName: '图片详情',
                        path: "/details"
                    },
                    {
                        id: 1.3,
                        authName: '卡密兑换',
                        path: "/cami"
                    },
                ]
            },
            {
                id: 2,
                authName: "个人资料",
                icon: "el-icon-s-check",
                children: [{
                    id: 2.1,
                    authName: "修改密码",
                    path: '/editpwd'
                }]
            },
            {
                id: 3,
                authName: "API接口",
                icon: "el-icon-key",
                path: "/api",
                children: [{
                    id: 3.1,
                    authName: "我的API",
                    path: '/api'
                }]
            },
            {
                id: 4,
                authName: "网站管理",
                icon: "el-icon-s-tools",
                children: [{
                        id: 4.1,
                        authName: "用户管理",
                        path: "/users"
                    },
                    {
                        id: 4.2,
                        authName: "卡密管理",
                        path: "/camis"
                    }
                ]
            }
        ]
        res.sendResult(arr, 200, '获取成功！')
    }
}